package com.ruoyi.activiti.controller;

import com.ruoyi.activiti.domain.ActMaintainOrder;
import com.ruoyi.activiti.domain.vo.ActMaintainOrderVO;
import com.ruoyi.activiti.service.IActMaintainOrderService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 维护单Controller
 *
 * @author cjie
 * @date 2021-12-19
 */
@Api(tags = " 维护单")
@RestController
@RequestMapping("/actMaintainOrder")
public class ActMaintainOrderController extends BaseController {
    @Autowired
    private IActMaintainOrderService actMaintainOrderService;

    /**
     * 查询维护单列表
     */
    @ApiOperation(value="查询维护单列表", notes="查询维护单列表")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(ActMaintainOrder actMaintainOrder) {
        startPage();
        List<ActMaintainOrder> list = actMaintainOrderService.selectActMaintainOrderList(actMaintainOrder);
        return getDataTable(list);
    }

    /**
     * 查询维护单数据列
     */
    @ApiOperation(value="查询维护单数据列", notes="查询维护单数据列")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrder:list")
    @GetMapping("/tableData/list")
    public TableDataInfo tableDatalist(ActMaintainOrder actMaintainOrder) {
        // 重写数据分页
        startPage();

        List<ActMaintainOrder> list = actMaintainOrderService.selectActMaintainOrderList(actMaintainOrder);
        return getDataTable(list);
    }

    /**
     * 导出维护单列表
     */
    @ApiOperation(value="导出维护单列表", notes="导出维护单列表")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrder:export")
    @Log(title = "维护单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActMaintainOrder actMaintainOrder) throws IOException {
        List<ActMaintainOrder> list = actMaintainOrderService.selectActMaintainOrderList(actMaintainOrder);
        ExcelUtil<ActMaintainOrder> util = new ExcelUtil<ActMaintainOrder>(ActMaintainOrder.class);
        util.exportExcel(response, list, "维护单数据");
    }
    /**
     * 获取维护单详细信息
     */
    @ApiOperation(value="获取维护单详细信息", notes="获取维护单详细信息")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrder:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(actMaintainOrderService.selectActMaintainOrderVOById(id));
    }

    /**
     * 获取维护单列
     */
    @ApiOperation(value="列数组", notes="获取维护单列详细信息")
    @GetMapping(value = "/cols/{id}")
    public AjaxResult getColsInfo(@PathVariable("id") String id) {
        //result.put("date",)
        return AjaxResult.success(actMaintainOrderService.selectFieldVOByFormId(id));
    }

    /**
     * 新增维护单
     */
    @ApiOperation(value="新增维护单", notes="新增维护单")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrder:add")
    @Log(title = "维护单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActMaintainOrderVO actMaintainOrderVO) {
        return toAjax(actMaintainOrderService.insertActMaintainOrderVO(actMaintainOrderVO));
    }

    /**
     * 修改维护单
     */
    @ApiOperation(value="修改维护单", notes="修改维护单")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrder:edit")
    @Log(title = "维护单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActMaintainOrderVO actMaintainOrderVO) {
        return toAjax(actMaintainOrderService.updateActMaintainOrderVO(actMaintainOrderVO));
    }

    /**
     * 删除维护单
     */
    @ApiOperation(value="删除维护单", notes="删除维护单")
    @ApiImplicitParam(name = "ids", value = "维护单ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "activiti:actMaintainOrder:remove")
    @Log(title = "维护单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(actMaintainOrderService.deleteActMaintainOrderByIds(ids));
    }
}
